from django.db import models
# Create your models here.
class User(models.Model):
    name = models.CharField(max_length=20)
    age = models.CharField(max_length=100)
# 和user表一对一关联
class UserExtension(models.Model):
    birthday = models.DateField()
    university = models.CharField(max_length=200)
    user = models.OneToOneField('User',on_delete=models.CASCADE)
# 和user表一对多关联
class Article(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    pub_time = models.DateTimeField(auto_now_add=True,null=True)
    # author外键
    # author = models.ForeignKey(User, on_delete=models.CASCADE)
    author = models.ForeignKey(User, on_delete=models.SET_DEFAULT, default=1, related_name='articles')
    # author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    tags = models.ManyToManyField('Tag', related_name='articles')
class Tag(models.Model):
    name = models.CharField(max_length=100)
class Comment(models.Model):
    content = models.TextField()
    origin_comment = models.ForeignKey('self', on_delete=models.CASCADE, null=True)
